﻿/// <reference path="../../Scripts/jquery/jquery-1.4.1-vsdoc.js" />
var currentLpId = null, currentNameLink = null, currentUserId = null;
$(function() {
    $('.requestbutton').click(function() {
        InitializeSendPanel();
        currentNameLink = $(this).parents('div.lpmatchresult').find('a.namelink').attr("target", "_blank");
        var span = $('.dialogform .requesteelink');
        span.empty();
        currentNameLink.clone().removeAttr("id").appendTo(span);
        var t = $(this).attr("rel").split("|");
        currentLpId = t[0];
        currentUserId = t[1];

        OpenJqueryDialog();
    });

    $('#sendrequestbutton').click(SendRequest);
});

function SendRequest() {
    if (currentLpId != null && currentNameLink != null && currentUserId!=null) {
        $(this).attr("disabled", true);
        $.post("LearningWebService.asmx/SendLearningRequest", {
        requesteeLpId: currentLpId,
        requesteeUserId: currentUserId,
        requestorLpId: $('#requestorLpid').val(),
        requestorUserId: userid,
        comment: $('#requesteecomment').val()
        }, RequestSentCallBack);
    }
    else {
        alert("无法发送邀请。");
    }
}

function RequestSentCallBack(data) {
    var success;
    if ($.browser.msie) {
        success = eval(data.text);
    }
    else {
        success = true;
    }
    
    if (!success) {
        alert("发送失败。");
    }
    else {
        $('div#readytosend').hide();
        $('div#sendsuccess').show();
    }
    $('#sendrequestbutton').attr("disabled", false);
}

function InitializeSendPanel() {
    $('div#readytosend').show();
    $('div#sendsuccess').hide();
    currentLpId = null;
    currentNameLink = null;
    currentUserId = null;
    $('#requesteecomment').val("");
}